/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.rukopisy.tools.cli;

import cz.mzk.kramerius.rukopisy.tools.ItemsTransferBuilder;
import cz.mzk.kramerius.rukopisy.tools.TeiManager;
import cz.mzk.oai.metadataRepository.harvest.tei.svn.SignatureSysnoMapper;
import cz.mzk.oai.metadataRepository.repository.Repository;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 *
 * Creates item transfer scripts for manuscripts according to whether source collection (from which
 * to move) and they are digitized.
 */
public class BuildItemTransfersAction implements Action {

    private final ItemsTransferBuilder builder;

    public BuildItemTransfersAction(String properties, String mapperFile, String resultDirPath, String teiDir) throws Exception {
        Repository repository = getRepository(properties);
        File resultDir = new File(resultDirPath);
        SignatureSysnoMapper mapper = new SignatureSysnoMapper(new File(mapperFile));
        TeiManager teiManager = new TeiManager(new File(teiDir));
        builder = new ItemsTransferBuilder(repository, mapper, teiManager, resultDir);
    }

    private Repository getRepository(String propertiesFile) throws IOException {
        Properties properties = new Properties();
        properties.load(new FileInputStream(new File(propertiesFile)));
        return Repository.instanceOf(properties);
    }

    public void run() {
        builder.buildTransferFiles();
    }
}
